package com.zxt.service;

import com.zxt.dao.BookMapper;
import com.zxt.pojo.Books;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

//service层调dao层
@Service
public class BookServiceImpl implements BookService{
    @Resource
    private BookMapper bookMapper;

    public void setBookMapper(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }

    @Override
    public int addBook(Books books) {
        //return bookMapper.addBook(books);
        return bookMapper.insert(books);
    }

    @Override
    public int deleteBookById(int id) {
        //return bookMapper.deleteBookById(id);
        HashMap hashMap = new HashMap();
        hashMap.put("bookId",id);
        return bookMapper.deleteByMap(hashMap);
    }

    @Override
    public int updateBook(Books books) {
        return bookMapper.updateById(books);
    }

    @Override
    public Books queryBookById(int id) {
        //return bookMapper.queryBookById(id);
        return bookMapper.selectById(id);
    }

    @Override
    public List<Books> queryAllBooks() {
        //return bookMapper.queryAllBooks();
        return bookMapper.selectList(null);
    }

    @Override
    public List<Books> queryBooksByName(String name) {
        return bookMapper.queryBooksByName(name);
    }
}
